package cn.ciis.sys.taxonomy;

import cn.ciis.basic.base.BaseController;
import cn.ciis.basic.model.Taxonomy;
import cn.ciis.sys.menu.MenuAdminService;
import cn.ciis.sys.permission.Notes;
import cn.ciis.sys.permission.Remark;
import com.jfinal.aop.Aop;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * 角色管理控制器
 *
 * @author 冉志林
 */
public class TaxonomyAdminController extends BaseController {

  @Inject TaxonomyAdminService srv;

  @Notes(value = "系统分类管理")
  @Remark(value = "系统分类列表")
  public void index() {
    Taxonomy mode = getModel(Taxonomy.class, "", true);
    kModel(mode, srv.paginate(getInt(PAGENUMBER, 1), getInt(PAGESIZE, 10), mode));
  }

  @Remark(value = "系统分类添加或编辑页")
  public void addOrEdit(Integer id) {
    kAddOrEdit(srv.findById(id));
  }

  @Remark(value = "系统分类保存或修改")
  @Before(TaxonomyAdminValidator.class)
  public void saveOrUpdate() {
    Taxonomy bean = getBean(Taxonomy.class);
    renderJson(srv.saveOrUpdate(bean));
  }

  @Remark(value = "系统分类删除")
  public void deletes(String ids) {
    renderJson(srv.deletes(ids));
  }

  @Remark(value = "选择菜单")
  public void choiceMenu(Integer id) {
    if (null != id) {
      MenuAdminService menuService = Aop.get(MenuAdminService.class);
      List<Record> allMenu = menuService.getAllMenu();
      set("menuMap", menuService.groutBySuperior(allMenu, getLoginAccountId()));
    }
  }

  @Remark(value = "系统状态修改")
  public void updateEnable(String id,String type){
    renderJson(srv.updatePk("sys_taxonomy",id,"isEnable",type));
  }
}
